feat: add stats/base/dists/log-logistic/pdf#11203
feat: add stats/base/dists/log-logistic/pdf#11203parthodas23 wants to merge 1 commit intostdlib-js:developfrom
stats/base/dists/log-logistic/pdf#11203Conversation
Coverage Report
The above coverage report was generated for the changes in this PR. |
5cf562d to
13f4fad
Compare
13f4fad to
cbec15c
Compare
| import Distributions: pdf, Log-logistic | ||
| import JSON |
There was a problem hiding this comment.
Julia doesn't have log-logistic or fisk distribution. For that reason upon running this script, module import error takes place. Scipy has fisk distribution, but the parameterization is different. Refer to scipy docs for more info. This pdf function import for log logistic isn't even used in later part of the script.
| function gen( x, alpha, beta, name ) | ||
| z = Array{Float64}( undef, length(x) ); | ||
| for i in eachindex(x) | ||
| if x[i] < 0.0 | ||
| z[i] = 0.0; | ||
| else | ||
| r = x[i] / alpha[i]; | ||
| z[i] = (beta[i] / alpha[i]) * r^(beta[i] - 1.0) / (1.0 + r^beta[i])^2; | ||
| end | ||
| end |
There was a problem hiding this comment.
To generate fixtures, generally already implemented library functions are used. For this case use scipy fisk distribution pdf.
| y = pdf( NaN, 1.0, 1.0 ); | ||
| t.strictEqual( isnan( y ), true, 'returns expected value' ); | ||
|
|
||
| y = pdf( 0.5, NaN, 1.0 ); | ||
| t.strictEqual( isnan( y ), true, 'returns expected value' ); | ||
|
|
||
| y = pdf( 0.5, 1.0, NaN ); | ||
| t.strictEqual( isnan( y ), true, 'returns expected value' ); | ||
|
|
||
| y = pdf( NaN, NaN, NaN ); | ||
| t.strictEqual( isnan( y ), true, 'returns expected value' ); |
There was a problem hiding this comment.
| y = pdf( NaN, 1.0, 1.0 ); | |
| t.strictEqual( isnan( y ), true, 'returns expected value' ); | |
| y = pdf( 0.5, NaN, 1.0 ); | |
| t.strictEqual( isnan( y ), true, 'returns expected value' ); | |
| y = pdf( 0.5, 1.0, NaN ); | |
| t.strictEqual( isnan( y ), true, 'returns expected value' ); | |
| y = pdf( NaN, NaN, NaN ); | |
| t.strictEqual( isnan( y ), true, 'returns expected value' ); | |
| y = pdf( NaN, 1.0, 1.0 ); | |
| t.strictEqual( isnan( y ), true, 'returns expected value' ); | |
| y = pdf( 0.5, NaN, 1.0 ); | |
| t.strictEqual( isnan( y ), true, 'returns expected value' ); | |
| y = pdf( 0.5, 1.0, NaN ); | |
| t.strictEqual( isnan( y ), true, 'returns expected value' ); | |
| y = pdf( NaN, 1.0, NaN ); | |
| t.strictEqual( isnan( y ), true, 'returns expected value' ); | |
| y = pdf( NaN, NaN, 1.0 ); | |
| t.strictEqual( isnan( y ), true, 'returns expected value' ); | |
| y = pdf( 0.5, NaN, NaN ); | |
| t.strictEqual( isnan( y ), true, 'returns expected value' ); | |
| y = pdf( NaN, NaN, NaN ); | |
| t.strictEqual( isnan( y ), true, 'returns expected value' ); |
There was a problem hiding this comment.
Refer to normal dist pdf tests. All 3 combinations of two NaN occurences should also be tested.
| y = pdf( -1.0, 1.0, 1.0 ); | ||
| t.strictEqual( y, 0.0, 'returns expected value' ); | ||
|
|
||
| y = pdf( -10.0, 2.0, 3.0 ); | ||
| t.strictEqual( y, 0.0, 'returns expected value' ); |
There was a problem hiding this comment.
Both of these test cases test the same thing. My suggestion would be to remove one of them, since both of them check for x<0
manit2004
left a comment
There was a problem hiding this comment.
comments made for test.pdf.js is also applicable for test.native.js and test.factory.js
|
|
||
| y = pdf( 1.0, 1.0, NINF ); | ||
| t.strictEqual( isnan( y ), true, 'returns expected value' ); | ||
|
|
There was a problem hiding this comment.
| y = pdf( 1.0, PINF, NINF ); | |
| t.strictEqual( isnan( y ), true, 'returns expected value' ); | |
| y = pdf( 1.0, NaN, NINF ); | |
| t.strictEqual( isnan( y ), true, 'returns expected value' ); | |
| y = pdf( 1.0, NINF, NINF ); | |
| t.strictEqual( isnan( y ), true, 'returns expected value' ); |
Refer to normal pdf tests, combinations of PINF and NaN should also be added with NINF. Import PINF at the top of the file. Same for non positive alpha test cases.
| beta = data.beta; | ||
| for ( i = 0; i < x.length; i++ ) { | ||
| y = pdf( x[ i ], alpha[ i ], beta[ i ] ); | ||
| if ( expected[ i ] !== null && !( expected[ i ] === 0.0 && y < EPS ) ) { |
There was a problem hiding this comment.
| if ( expected[ i ] !== null && !( expected[ i ] === 0.0 && y < EPS ) ) { | |
| if ( expected[ i ] !== null && !( expected[ i ] === 0.0 && y < EPS ) ) |
!( expected[ i ] === 0.0 && y < EPS this expression is not needed. In your Julia Script x can be equal to 0 thus it's a valid possibilty that expected[ i ] === 0.0 and y can be very small. In normal pdf tests or any other test files we don't use this. Also expected[ i ] !== null is unnecessary, fixtures are already reliably generated.
| t.ok( delta <= tol, 'within tolerance. x: '+x[ i ]+'. alpha: '+alpha[ i ]+'. beta: '+beta[ i ]+'. y: '+y+'. E: '+expected[ i ]+'. Δ: '+delta+'. tol: '+tol+'.' ); | ||
| } |
There was a problem hiding this comment.
use @stdlib/assert/is-almost-same-value' instead of delta tolerance tests
There was a problem hiding this comment.
These images are auto generated, we can remove this file
| int i; | ||
|
|
||
| for ( i = 0; i < 100; i++ ) { | ||
| x[ i ] = random_uniform( STDLIB_CONSTANT_FLOAT64_EPS, 20.0 ); |
There was a problem hiding this comment.
| x[ i ] = random_uniform( STDLIB_CONSTANT_FLOAT64_EPS, 20.0 ); | |
| x[ i ] = random_uniform( 0.0, 20.0 ); |
the domain for x is [0,inf) so here the lower bound should be zero.
| opts = { | ||
| 'dtype': 'float64' | ||
| }; | ||
| x = uniform( 100, EPS, 20.0, opts ); |
There was a problem hiding this comment.
| x = uniform( 100, EPS, 20.0, opts ); | |
| x = uniform( 100, 0.0, 20.0, opts ); |
same comment
| opts = { | ||
| 'dtype': 'float64' | ||
| }; | ||
| x = uniform( 100, EPS, 20.0, opts ); |
There was a problem hiding this comment.
| x = uniform( 100, EPS, 20.0, opts ); | |
| x = uniform( 100, 0.0, 20.0, opts ); |
same comment.
| bopts = { | ||
| 'dtype': 'float64' | ||
| }; | ||
| x = uniform( 100, EPS, 20.0, bopts ); |
There was a problem hiding this comment.
| x = uniform( 100, EPS, 20.0, bopts ); | |
| x = uniform( 100, 0.0, 20.0, bopts ); |
same comment
| beta <= 0.0 | ||
| ) { | ||
| return constantFunction( NaN ); | ||
| } |
There was a problem hiding this comment.
before returning pdf function we can do some micro-optimization by precomputing beta/alpha and (beta -1) for the exponent.
|
comments made for test.pdf.js is also applicable for test.factory.js and test.native.js |
none
Description
This pull request:
stats/base/dists/log-logistic/pdfRelated Issues
This pull request has the following related issues:
Questions
No.
Other
No.
Checklist
AI Assistance
If you answered "yes" above, how did you use AI assistance?
Disclosure
{{TODO: add disclosure if applicable}}
@stdlib-js/reviewers